package com.hspedu.interface_;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/28
 * @time 11:01
 */
public class InterfacePolyArr {
    public static void main(String[] args) {
        Usb_[] usb_s = new Usb_[2];
        usb_s[0] = new Phone_();
        usb_s[1] = new Camera_();

        for (int i = 0; i < usb_s.length; i++) {
            usb_s[i].work();
            if (usb_s[i] instanceof Phone_){
                Phone_ phone_ = (Phone_) usb_s[i];
                phone_.call();
            }
        }
    }
}

interface Usb_{
    void work();
}

class Phone_ implements  Usb_{
    @Override
    public void work() {
        System.out.println("手机开始工作了");
    }
    public void call(){
        System.out.println("手机可以打电话");
    }
}

class Camera_ implements Usb_{
    @Override
    public void work() {
        System.out.println("相机开始工作了");
    }
}
